package com.hrt.common.db;

import com.btcode.db.result.PageResult;
import com.btcode.db.result.Row;
import com.btcode.db.sqlparameter.PageInfo;
import com.btcode.db.sqlparameter.SQLParameterList;
import com.btcode.orm.model.IModel;
import com.hrt.common.web.RequestUnit;
import java.util.List;

public class DataUtil {

    public static PageResult queryListPage(String sql, SQLParameterList parms) {
        PageInfo pageInfo = RequestUnit.getPageInfo();
        PageResult result = CommonDBManager.getDataExecuter().queryListPage(sql, parms, pageInfo);
        return result;
    }

    public static <T extends IModel> PageResult queryListPage(String sql, SQLParameterList parms,
        Class<T> modelClass) {
        PageInfo pageInfo = RequestUnit.getPageInfo();
        PageResult result = CommonDBManager.getDataExecuter().queryListPage(sql, parms, pageInfo);
        List<Row> data = result.getData();
        data = CommonDBManager.getORMExecuter().converDomain(data, modelClass);
        result.setData(data);
        return result;
    }

}
